package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.SysWorkLogEntity;
import io.renren.service.SysWorkLogService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-06-19 17:51:34
 */
@Controller
@RequestMapping("sysworklog")
public class SysWorkLogController {
	@Autowired
	private SysWorkLogService sysWorkLogService;
	
	@RequestMapping("/sysworklog.html")
	public String list(){
		return "sysworklog/sysworklog.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("sysworklog:list")
	public R list(Integer page, Integer limit,String sort,String order,String value,String calTime){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		map.put("value", value);
		map.put("calTime", calTime);
		if (sort.isEmpty() || sort == null) {
			map.put("orderby", " ORDER BY createtimeLogin desc ");
        } else {
            map.put("orderby", " order by " + sort + " " + order + " ");
        }
		
		//查询列表数据
		List<SysWorkLogEntity> sysWorkLogList = sysWorkLogService.queryList(map);
		int total = sysWorkLogService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(sysWorkLogList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sysworklog:info")
	public R info(@PathVariable("id") Long id){
		SysWorkLogEntity sysWorkLog = sysWorkLogService.queryObject(id);
		
		return R.ok().put("sysWorkLog", sysWorkLog);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("sysworklog:save")
	public R save(@RequestBody SysWorkLogEntity sysWorkLog){
		sysWorkLogService.save(sysWorkLog);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("sysworklog:update")
	public R update(@RequestBody SysWorkLogEntity sysWorkLog){
		sysWorkLogService.update(sysWorkLog);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("sysworklog:delete")
	public R delete(@RequestBody Long[] ids){
		sysWorkLogService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
